﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Weather
{
    public partial class frmWaiting : Form
    {
        public frmWaiting()
        {
            InitializeComponent();        
          
        }

        public string Message
        {
            get
            {
                return lblMsg.Text;
            }
            set
            {
                lblMsg.Text = value;
            }
        }

        private static System.Threading.Thread td;
        private static frmWaiting dlg;

        public static void DoTask(TaskMod task,string msg)
        {
            System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;
            Timer timer = new Timer(); 
            timer.Interval = 100;
            dlg = new frmWaiting();
            System.Threading.ThreadStart ts = new System.Threading.ThreadStart(task);
            td = new System.Threading.Thread(ts);
            td.Start();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
            dlg.Message = msg;
            dlg.ShowDialog();
            timer.Stop();
            timer = null;
            System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = true;
        }

        static void timer_Tick(object sender, EventArgs e)
        {
            if ((td != null&&!td .IsAlive)||td==null )
            {
                if (dlg != null)
                    dlg.Close();
            } 

        }

        public delegate void TaskMod(); 
    }
}